package org.anyin.gitee.cloud.lib.permission;

import cn.dev33.satoken.interceptor.SaAnnotationInterceptor;
import cn.dev33.satoken.stp.StpInterface;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class PermissionConfig implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new SaAnnotationInterceptor()).addPathPatterns("/**");
    }

    @Bean
    public StpInterface stpInterface(PermissionRoleService permissionService){
        return new StpInterfaceImpl(permissionService);
    }

    @Bean
    @ConditionalOnMissingBean(PermissionRoleService.class)
    public PermissionRoleService permissionService(){
        return new DefaultPermissionRoleServiceImpl();
    }
}
